//**********************************************************************************************
//*
//* CopyRight(c)2008， Myspace.cn
//*
//**********************************************************************************************
package reader.utils
{
	import flash.utils.Dictionary;
	/**
	 * URL分析
	 *  
	 * @author Qizhi Zhang
	 */
	public class URL
	{
		private var _url:String;
		private var _dic:Dictionary;
		//private var hmac:HMAC_SHA1;
		/**
		 * 构造函数
		 *
		 * @param url 统一资源定位符 (Uniform Resource Locator), 一般格式为 protocol://hostname[:port]/path/[;parameters][?query]#fragment  
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 8.5
		 * @tiptext
		 */
		public function URL( url:String )
		{
			this._url = url;
			this._dic = new Dictionary();
			
			this.init();
		}
		
		private function init():void
		{
			if(!this.query) return;
			var a:Array = this.query.split( "&" );
			
			for each( var i:String in a )
			{
				var _key:String = i.split( "=" )[ 0 ];
				var _value:String = i.split( "=" )[ 1 ];
				this._dic[ _key ] = _value;
			}
		}
		
		/**
		 * 获取hostname 
		 */
		public function get hostname():String
		{
			return this._url.split( "?" )[ 0 ];
		}
		
		/**
		 * 获取query 
		 */
		public function get query():String
		{
			return this._url.split( "?" )[ 1 ];
		}
		
		/**
		 * 获取URL参数值
		 */
		public function getQueryByName( key:String ):String
		{
			return this._dic[ key ];
		}
	}
}
